<#include "/WEB-INF/template/page/admin/system/appbanner/_form.ftl"/>
</form>
<script type="text/javascript">
    jQuery("#appbanner_add").ready(function () {
        $("#bannerimg").fileupload({
            url: "${CONTEXT_PATH}/updown/up",//文件上传地址，当然也可以直接写在input的data-url属性内
            formData: {upflag: "banner_img", downflag: "down"},//此处为上传分类标志
            done: function (e, data) {
                $("[name='m.imageurl']").val(data.result.url);
                alert("图片上传成功");
            }
        });

        // 定义验证参数
        var validateOptions = $.extend(CONST_VALIDATE.OPTION, {
            rules: {
                "m.name": {
                    required: true,
                    maxlength: 100
                },
                "m.url": {
                    required: true,
                    maxlength: 255
                },
                "m.type": {
                    required: true,
                    maxlength: 32
                },
                "m.orders": {
                    required: true,
                    digits:true,
                    min:0
                }
            },
            messages: {
                "m.name": {
                    required: "<i class='fa fa-exclamation tooltips'></i>请输入Banner名称",
                    maxlength: $.validator.format("<i class='fa fa-exclamation tooltips'></i>Banner名称不能大于{0}个字符")
                },
                "m.url": {
                    required: "<i class='fa fa-exclamation tooltips'></i>请输入Banner访问路径",
                    maxlength: $.validator.format("<i class='fa fa-exclamation tooltips'></i>访问路径不能大于{0}个字符")
                },
                "m.type": {
                    required: "<i class='fa fa-exclamation tooltips'></i>请输入Banner类型",
                    maxlength: $.validator.format("<i class='fa fa-exclamation tooltips'></i>Banner类型不能大于{0}个字符")
                },
                "m.orders": {
                    required: "<i class='fa fa-exclamation tooltips'></i>请输入Banner排序",
                    digits: "<i class='fa fa-exclamation tooltips'></i>请输入大于0的整数",
                    min: $.validator.format("<i class='fa fa-exclamation tooltips'></i>播放次数不能小于{0}")
                }
            },
            submitHandler:function(form) {
                var modal = $("#ajax_add");
                $(form).ajaxSubmit(function (data, status, xhr) {
                    if (data.status) {
                        toastr.success(data.msg, '操作提示');
                    } else {
                        toastr.error(data.msg, '操作提示');
                    }
                });
                $(modal).modal('hide');
                dtgrid.load();
            }
        });
        //表单验证
        var validator = $("#appbanner_add").validate(validateOptions);
    });
</script>
